/**
 *
 */
package com.iknight.mgr.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iknight.mgr.api.AttachmentService;
import com.iknight.mgr.mapper.AttachmentMapper;
import com.iknight.mgr.model.AttachmentModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 */
@Service
public class AttachmentServiceImpl implements AttachmentService<AttachmentModel, String> {

    @Autowired
    private AttachmentMapper<AttachmentModel, String> attachmentMapper;

    public void save(AttachmentModel record) {
        // TODO Auto-generated method stub
        if (attachmentMapper.selectOne(record.getAttachment_id()) != null) {
            attachmentMapper.update(record);
        } else {
            attachmentMapper.insert(record);
        }
    }


    public void delete(String pkey) {
        // TODO Auto-generated method stub
        attachmentMapper.delete(pkey);
    }


    public AttachmentModel selectOne(String pkey) {
        // TODO Auto-generated method stub
        return attachmentMapper.selectOne(pkey);
    }


    public PageInfo<AttachmentModel> selectPage(Map<String, Object> params, int pageStart, int pageSize) {
        // TODO Auto-generated method stub
        PageHelper.startPage(pageStart, pageSize, true);
        List<AttachmentModel> fileList = attachmentMapper.selectByCond(params);
        PageInfo<AttachmentModel> page = new PageInfo<AttachmentModel>(fileList);
        return page;
    }


    public void abate(String fileId) {
        // TODO Auto-generated method stub
        attachmentMapper.abate(fileId);
    }

}
